DAS utilizing GPU

Created by Paul Klippel in May 2022


This notebook will run and then plot using Delay and Sum photoacoustic image reconstruction method.

The Delay and Sum algorithm works by synchronizing the arrival times for an array of transducer elements, summing their values, and averaging. The result represents the initial pressure value for a discrete point in space. Repeated over a region in space and one can create an initial pressure image from the photoacoustic energy transfer function.


Import Packages

Kernel Function: InitIndexMat
Inputs:

xImageLocs: all x-values for each reconstructed pixel
yImageLocs: all y-values for each reconstructed pixel
sensorLocs: [x, y] position for each element
indexMat: empty matrix for each the corresponding index of each element's pixel
signalLength: length of rfdata's first dimension
sos: medium speed of sound
dt: inverse of the sampling frequency for rfdata

Output:

N/A

Purpose: To calculate the index matrix for each pixel and element. It assumes that indexMat will be used to index a flattened signal matrix

Class Name: VariableSetup
Inputs:

filepath: exact file location for the .mat datafile
xlims: min and max values for the x-axis in the reconstruction region  
ylims: min and max values for the y-axis in the reconstruction region  
res: pixel resolution in the reconstruction region  

Attributes(memory host):

.sens_count(CPU): number of transducer elements  
.rfdataALL(CPU): If more than one frame is present this holds all frames
.rfdata(GPU): time vector with pressure values for the first frame recorded by each element  
.sensLocs(CPU): [x, y] position for each element   
.c0(CPU): medium speed of sound  
.dt(CPU): inverse of the sampling frequency  
.xMat(CPU): all x-values for each reconstructed pixel  
.yMat(CPU): all y-values for each reconstructed pixel  
.allIndex(GPU): indeces corresponding to each pixel in the layered delay matrix for all elements  
    l x m x n, l - corresponding to each element layer, m x n - corresponding to the reconstruction region

Methods:

__init__(self, filepath, xlims, ylims, res):
    initialize a VariableSetup object with attributes above and one conditional;
    For multiple frame rfdata, only the first frame is sent to the GPU.

SetupGPU(self, tb_shape):
    create the index matrix for all image reconstruction frames, calls above "InitIndexMat" kernel function on cuda.
    Inputs:
        self - VariableSetup object
        tb_shape - threads per block shape for cuda kernels
    Return:
        blocks_grid - shape of the blocks per grid for future image reconstruction

Purpose: To hold the necessary information for calculating DAS images given a constant system setup and speed of sound.

Kernel Function: FrameImaging
Inputs:

indexArr: Array from VariableSetup class .allIndex
valueArr: Flattened array from VariableSetup class .rfdata, only one "frame" at a time.
outputArr: Array with the same shape and size as the indexArr, used to store initial pressure values for each pixel

Output:

N/A

Purpose: To calculate the initial pressure values for each pixel averaged by each transducer element.

Main Function


Setup Variables- This is only done for the first frame, setting up the index matrix

Create the image- This can be run in a loop with multiple frame rfdata, re-assigning rfdata for each frame

Show the Reconstruction- optional to view the reconstructed image


END OF MAIN PROGRAM


Below are code blocks for time comparison between CPU and GPU implementations

GPU based function

This section records the time required for 10 iterations of the gpu accelerated reconstruction.

CPU based function

This section records the time required for 10 iterations of the cpu based reconstruction.

Reconstruction agreement has already been verified elsewhere.

Future improvements: